package com.fuchuang.seckillsystem.service.impl;

import com.fuchuang.seckillsystem.entity.MyUserDetails;
import com.fuchuang.seckillsystem.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;


@Service
public class UserDetailServiceImpl implements UserDetailsService {
    
    @Autowired
    private IUserService userService;
    
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        //从数据库中查询对于username的用户信息
        MyUserDetails userDetails = userService.findUserDetailsByUsername(s);
        if (Objects.isNull(userDetails)) {
            throw new UsernameNotFoundException("用户名称不存在");
        }
        return userDetails;
    }
}
